ComboBox Class

A data entry control that is similar to the PopupMenu, but allows for either selection from a list or keyboard entry. It behaves like a single-line EditField that has a popup menu attached to it.

Events

GotFocus

KeyDown

LostFocus

TextChanged


Properties

AutoComplete

SelLength

SelStart

Text

UseFocusRing


Methods

None

More information available in parent classes: PopupMenu:RectControl:Control:Object

The ComboBox can get the focus on all platforms.

Because this is a RectControl, see the RectControl for other properties and events that are common to all RectControl objects.


Examples

This code in the Open event handler populates a ComboBox and sets the initial value to the current month:

Dim s as String
Dim i,last as Integer
Dim d as New Date
s="January,February,March,April,May,June,July," _
     +"August,September,October,November,December"
last= CountFields(s,",")
For i=1 to last
 me.addRow NthField(s,",",i)
Next
me.ListIndex=d.Month-1

The value of the ListIndex property contains the index of the selected item, but it does not indicate whether the user has entered text into the ComboBox. Examine the Text property to get the current menu selection or the text entered by the user. For example, the following line in the TextChanged event handler displays either the currently selected menu item or the text typed into the ComboBox.

StaticText1.Text=Me.Text

This example adds an item to a ComboBox in its Open event handler

Me.addrow "October"

.

This example populates the RowTag identifier with a sequence number

Dim i,nItems as Integer
nItems= Me.ListCount-1
For i=0 to nitems
  Me.rowTag(i)=i
Next

:

Since RowTag is a Variant, you must first convert it to an Integer if you want to compare it to another integer. Do this with a simple assignment statement such as:

Dim RecID as Integer
RecID=ComboBox1.Rowtag(1)

Then compare RecID to another Integer.

This example opens a new window when an item is chosen.

Sub Change()
Dim w As ListEditorWindow
  If ComboBox1.text="Edit List..." Then
    w= New ListEditorWindow
  End If

The following line changes the selected item in a ComboBox

ComboBox1.listIndex=3

:

Displaying the RowTag of the selected menu item:

EditField1.text=ComboBox1.rowtag(ComboBox1.listindex)

See Also

ContextualMenu, EditField, PopupMenu controls; RectControl class.